/**
 * 
 */
package com.xbang.attendance.web.action.system.maintenance;

import java.io.File;
import java.util.Date;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.xbang.attendance.service.AnalyzeService;
import com.demo2do.lighturl.annotation.Action;
import com.xbang.core.struts.support.BaseActionSupport;
import com.xbang.core.utils.DateUtils;
import com.xbang.core.utils.FileUtils;

/**
 * @author dev.zhang
 * 
 */
public class Import extends BaseActionSupport {

	private static final long serialVersionUID = 4037486937918127712L;

	@Autowired
	@Qualifier("maintenanceAnalyzeService") 
	private AnalyzeService maintenanceAnalyzeService;

	private File file;

	private String fileFileName;

	private String fileContentType;

	public String execute() throws Exception {
		return "import";
	}

	/**
	 * @return
	 * @throws Exception
	 */
	@Action("/system/maintenance/import/do")
	public String doImport() throws Exception {
		/** 名称是否替换 */
		boolean isReplace = false;

		String ext = fileFileName.substring(fileFileName.lastIndexOf(".")).toLowerCase();
		String newFile = "maintenance-".concat(DateUtils.format(new Date(), "yyyyMMddhhmmss")).concat(ext);

		File indentFile = FileUtils.uploadFile(file, ServletActionContext.getRequest().getRealPath("/upload/system/maintenance"), getFileFileName(), newFile, isReplace);

		if (indentFile != null) {
			maintenanceAnalyzeService.analyse(indentFile);
		}
		return "r:/system/maintenance/list";
	}

	/**
	 * @return the file
	 */
	public File getFile() {
		return file;
	}

	/**
	 * @param file
	 *            the file to set
	 */
	public void setFile(File file) {
		this.file = file;
	}

	/**
	 * @return the fileFileName
	 */
	public String getFileFileName() {
		return fileFileName;
	}

	/**
	 * @param fileFileName
	 *            the fileFileName to set
	 */
	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}

	/**
	 * @return the fileContentType
	 */
	public String getFileContentType() {
		return fileContentType;
	}

	/**
	 * @param fileContentType
	 *            the fileContentType to set
	 */
	public void setFileContentType(String fileContentType) {
		this.fileContentType = fileContentType;
	}



	
}
